import moment from "moment";

export default {
    namespaced: true,
    state: {
        websocket: null,
        messages: []
    },
    getters: {
        websocket: (state) => state.websocket,
        messages: (state) => state.messages,
    },
    actions: {
        setWebsocket ({commit}, websocket) {
            commit('setWebsocket', websocket);
        },
        setMessages ({commit}, msg) {
            msg.time = moment(msg.time).format('YYYY-MM-DD HH:mm:ss')
            commit('setMessages', msg);
        }
    },
    mutations: {
        setWebsocket (state, websocket) {
            state.websocket = websocket
        },
        setMessages (state, msg) {
            state.messages.push(msg);
        }
    },
}
